package flc.ast.fragment;

import androidx.fragment.app.Fragment;

import android.view.View;

import com.stark.game2048.lib.constant.G2048OpenProvider;

import java.util.Random;

import flc.ast.activity.GameActivity;
import flc.ast.R;
import flc.ast.databinding.FragmentGameBinding;
import stark.common.basic.base.BaseNoModelFragment;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link GameFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class GameFragment extends BaseNoModelFragment<FragmentGameBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_game;
    }

    @Override
    protected void initView() {
        mDataBinding.rlGame128.setOnClickListener(this);
        mDataBinding.rlGame1024.setOnClickListener(this);
        mDataBinding.rlGame2048.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.rlGame128:
                GameActivity.mOpenStateInfo=G2048OpenProvider.getOpenInfos().get(1);
                GameActivity.type=0;
                startActivity(GameActivity.class);
                break;
            case R.id.rlGame1024:
                GameActivity.mOpenStateInfo=G2048OpenProvider.getOpenInfos().get(4);
                GameActivity.type=1;
                startActivity(GameActivity.class);
                break;
            case R.id.rlGame2048:
                GameActivity.mOpenStateInfo=G2048OpenProvider.getOpenInfos().get(5);
                GameActivity.type=2;
                startActivity(GameActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        Random random=new Random();
        mDataBinding.tvGame128Num.setText(random.nextInt(100)+1000+"");
        mDataBinding.tvGame1024Num.setText(random.nextInt(100)+1000+"");
        mDataBinding.tvGame2048Num.setText(random.nextInt(100)+1000+"");
    }
}